package com.lxmes.hr.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcAttendBase;
import com.lxmes.hr.service.INcAttendBaseService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 考勤基数Controller
 *
 * @author ruoyi
 * @date 2023-02-17
 */
@RestController
@RequestMapping("/hr/attendBase")
public class NcAttendBaseController extends BaseController
{
    @Autowired
    private INcAttendBaseService ncAttendBaseService;

    /**
     * 查询考勤基数列表
     */
    @PreAuthorize("@ss.hasPermi('hr:attendBase:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcAttendBase ncAttendBase)
    {
        startPage();
        List<NcAttendBase> list = ncAttendBaseService.selectNcAttendBaseList(ncAttendBase);
        return getDataTable(list);
    }

    /**
     * 导出考勤基数列表
     */
    @PreAuthorize("@ss.hasPermi('hr:attendBase:export')")
    @Log(title = "考勤基数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcAttendBase ncAttendBase)
    {
        List<NcAttendBase> list = ncAttendBaseService.selectNcAttendBaseList(ncAttendBase);
        ExcelUtil<NcAttendBase> util = new ExcelUtil<NcAttendBase>(NcAttendBase.class);
        util.exportExcel(response, list, "考勤基数数据");
    }

    /**
     * 获取考勤基数详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:attendBase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncAttendBaseService.selectNcAttendBaseById(id));
    }

    /**
     * 新增考勤基数
     */
    @PreAuthorize("@ss.hasPermi('hr:attendBase:add')")
    @Log(title = "考勤基数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcAttendBase ncAttendBase)
    {
        return toAjax(ncAttendBaseService.insertNcAttendBase(ncAttendBase));
    }

    /**
     * 修改考勤基数
     */
    @PreAuthorize("@ss.hasPermi('hr:attendBase:edit')")
    @Log(title = "考勤基数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcAttendBase ncAttendBase)
    {
        return toAjax(ncAttendBaseService.updateNcAttendBase(ncAttendBase));
    }

    /**
     * 删除考勤基数
     */
    @PreAuthorize("@ss.hasPermi('hr:attendBase:remove')")
    @Log(title = "考勤基数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncAttendBaseService.deleteNcAttendBaseByIds(ids));
    }

    /**
     * 导入考勤基数
     */
    @Log(title = "考勤基数", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcAttendBase> util = new ExcelUtil<>(NcAttendBase.class);
        List<NcAttendBase> ncAttendBaseList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncAttendBaseService.imporIteminfo(ncAttendBaseList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcAttendBase> util = new ExcelUtil<>(NcAttendBase.class);
        util.importTemplateExcel(response,"考勤基数");
    }
}
